package main.command;

import java.util.ArrayList;
import java.util.List;

public class Switch {

    private Command turnOnCommand;
    private Command turnOffCommand;
    // private Command undoCommand;
    private List<Command> historyList;

    public Switch() {
	historyList = new ArrayList<Command>();
    }

    public void setCommand(Command onCommand, Command offCommand) {
	this.turnOnCommand = onCommand;
	this.turnOffCommand = offCommand;
    }

    public void turnOn() {
	this.turnOnCommand.execute();
	this.historyList.add(this.turnOnCommand);
	// this.undoCommand = this.turnOnCommand;
    }

    public void turnOff() {
	this.turnOffCommand.execute();
	this.historyList.add(this.turnOffCommand);
	// this.undoCommand = this.turnOffCommand;
    }

    public void undo() {
	/*
	 * if(undoCommand != null){ undoCommand.undo(); }
	 */
	if (this.historyList != null && this.historyList.size() > 0) {
	    historyList.get(historyList.size() - 1).undo();
	    historyList.remove(historyList.size() - 1);
	}
    }
}
